package com.ysx.oa.resume.controller;

import com.ysx.oa.resume.Bean.QuestionBean;
import com.ysx.oa.resume.Bean.ResumeBean;
import com.ysx.oa.resume.entity.ResumeEntity;
import com.ysx.oa.resume.service.QuestionService;
import com.ysx.oa.resume.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    @Autowired
    private QuestionService questionService;


//======================================  学生调用的Controller ======================================

    /**
     * 方法描述: 【学生】 添加 面试记录信息
     * URL: localhost:8080/kaoqin/resume/addResumeByStudentId
     * {
     *     "STUDENT_ID"        : 100001,
     *     "COMPANY_ID"        : 6,
     *     "JOB_ID"            : 2,
     *     "DATE"              : "2021-01-01",
     *     "STUDENT_APPRAISAL" : "测试请求学生评价",
     *     "REMARK"            : "测试请求学生备注"
     * }
     * @author: 黄德标
     * @date: 2021/11/23 21:54
     * @param: resumeEntity
     */
    @RequestMapping(value = "/addResumeByStudentId",method = RequestMethod.POST)
    public Map<String,Object> addResumeByStudentId(@RequestBody ResumeEntity resumeEntity){
        Map<String,Object> map = new HashMap<>();
        String str = null;
        int rs = resumeService.addResumeEntityByStudentId(resumeEntity);
        if (rs == 1){
            str = "添加成功";
        }else if (rs == 2){
            str = "学号不存在，请重试";
        }else if (rs == 3){
            str = "公司参数有误，请重试";
        }else if (rs == 4){
            str = "岗位参数有误，请重试";
        }else if (rs == 5){
            str = "学生评价内容过长，不应该超过255个字符";
        }else if (rs == 6){
            str = "学生备注内容过长，不应该超过255个字符";
        }
        map.put("code",200);
        map.put("message","success");
        map.put("data",str);
        return map;
    }


    /**
     * 方法描述: 【学生】 查找 自己所有的 面试记录信息
     * URL: localhost:8080/kaoqin/resume/findResumeByStudentId?studentId=100001
     * @author: 黄德标
     * @date: 2021/11/23 19:59
     * @param: studentId
     */
    @RequestMapping(value = "/findResumeByStudentId",method = RequestMethod.GET)
    public Map<String,Object> findResumeByStudentId(Integer studentId){
        Map<String,Object> map = new HashMap<>();

        ArrayList<ResumeBean> resumeBeanArrayList
                = resumeService.selectResumeBeanByStudentId(studentId);

        map.put("code",200);
        map.put("message","success");
        map.put("data",resumeBeanArrayList);
        return map;
    }


    /**
     * 方法描述: 【学生】 查找 自己的 一个详细的面试记录（面试记录信息及面试中的问答）
     * URL: localhost:8080/kaoqin/resume/findResumeByResumeId?resumeId=3
     * @author: 黄德标
     * @date: 2021/11/23 20:04
     * @param: resumeId
     */
    @RequestMapping(value = "/findResumeByResumeId",method = RequestMethod.GET)
    public Map<String,Object> findResumeByResumeId(Integer resumeId){
        Map<String,Object> map = new HashMap<>();

        ResumeBean resumeBean
                = resumeService.selectResumeBeanByResumeId(resumeId);

        map.put("code",200);
        map.put("message","success");
        map.put("data",resumeBean);
        return map;
    }

//======================================  老师调用的Controller ======================================

    /**
     * 方法描述: 【老师】 查找 自己本班 所有学生 的面试记录
     * URL: localhost:8080/kaoqin/resume/findResumeByTeacherId?teacherId=100007
     * @author: 黄德标
     * @date: 2021/11/25 17:02
     * @param: resumeId
     */
    @RequestMapping(value = "/findResumeByTeacherId",method = RequestMethod.GET)
    public Map<String,Object> findResumeByTeacherId(Integer teacherId){
        Map<String,Object> map = new HashMap<>();

        ArrayList<ResumeBean> resumeBeanArrayList = resumeService.findResumeByTeacherId(teacherId);

        map.put("code",200);
        map.put("message","success");
        map.put("data",resumeBeanArrayList);
        return map;
    }






}
